const toolsObj = {
	age: '年龄',
	bloodGlucose: '血糖(mmol / L)',
	bloodOxygen: '血氧',
	bloodPressure: '血压(mmHg)',
	updateTime: '记录时间',
	height: '身高(单位cm)',
	pressure: '压力值',
	remark: '备注',
	weight: '体重(单位kg)'
}

export const filterSwitch = (item) => {
	if (toolsObj[item]) {
		return toolsObj[item]
	}
}

export const requiredRules = () => {
	const obj = {
		required: true,
		message: '请填写数据'
	}
	return obj
}
export const numberRules = () => {
	const obj = {
		type: 'number',
		message: '请填写数字'
	}
	return obj
}
export const mapSalesmanList = (arr, type) => {
	const newArr = []
	if (type === 'shop') {
		arr.forEach(item => {
			newArr.push({
				text: item.username,
				value: item.code
			})
		})
	} else if (type === 'Marketing') {
		arr.forEach(item => {
			newArr.push({
				text: item.name,
				value: item.memberCode,
			})
		})
	}
	return newArr
}

export const filterGoods = (arr, price) => {
	const newArr = []
	console.log('提交订单前设置商品明细', arr)
	arr.forEach(item => {
		newArr.push({
			amount: item.number || 1,
			itemArr: item.itemArr || item.productAttrValues[0].skuValue,
			productCode: item.code || item.uniqueId,
			integral: item.integral,
			productName: item.name || item.commodityName,
			productImage: item.picUrl || item.images[0].url,
			enterpriseCode: item.isGroupBuying == '0' ? item.enterpriseCode : JSON.parse(uni.getStorageSync('ylEnterprise') || '{}').enterpriseCode,
			unitPrice:item.isGroupBuying == '0' ? item.groupBuyPrice : (item.price || item.salesPrice),
			productIntro: item.intro || item.description
		})
	})
	return newArr
}

export const nonceStr = () => {
	const str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	let Str = ''
	for (let i = 0; i < 32; i++) {
		const radomNum = Math.floor(Math.random() * (str.length + 1)) //含最大值，含最小值
		Str = Str + str[radomNum]
	}
	return Str
}

//倒计时
export const getCountDown = (endTime) => {
	let Str = ''
	//获取当前时间  //获取结束时间 剩余时间
	// 结束时间-当前时间 得到毫秒 , 转换成 时分秒
	const newDate = +new Date()
	const remaining = (endTime - newDate) / 1000 //得到秒
	let h = parseInt(remaining / 60 / 60 % 24);
	h < 10 ? h = "0" + h : ''
	let m = parseInt(remaining / 60 % 60);
	m < 10 ? m = "0" + m : m
	let s = parseInt(remaining % 60)
	s < 10 ? s = "0" + s : s
	Str = h + '小时' + m + '分' + s + '秒'
	return Str
}

//获取年月日
export const getYMD = () => {
	let myDate = new Date()
	let myMonth = myDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
	let myToday = myDate.getDate(); //获取当前日(1-31)
	myMonth = myMonth > 9 ? myMonth : '0' + myMonth
	myToday = myToday > 9 ? myToday : '0' + myToday
	let nowDate = myMonth + '.' + myToday + '新品'
	return nowDate
}
//获取时间格式
export const handleDate = (str) => {
	let obj = {
		createEnd: "",
		createStart: ""
	}
	let myDate = new Date()
	let myYear = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
	let myMonth = myDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
	let myToday = myDate.getDate(); //获取当前日(1-31)
	let y = myYear
	let m = myMonth
	let d = myToday
	let i = 0
	switch (myMonth) {
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10: {
			console.log('5yue')
			if (myToday < 31)
				d = myToday + 1;
			else if (myToday == 31) {
				m = myMonth + 1;
				d = 1;
			} else
				i++;
			break;
		}
		case 12: {
			if (myToday < 31)
				d = myToday + 1;
			else if (myToday == 31) {
				y = myYear + 1;
				m = 1;
				d = 1;
			} else
				i++;
			break;
		}
		case 4:
		case 6:
		case 9:
		case 11: {
			if (myToday < 30)
				d = myToday + 1;
			else if (myToday == 30) {
				m = myMonth + 1;
				d = 1;
			} else
				i++;
			break;
		}
		case 2: {
			if ((myYear % 4 == 0 && myYear % 100 != 0) || myYear % 400 == 0) {
				if (myToday < 29)
					d = myToday + 1;
				else if (myToday == 29) {
					m = 3;
					d = 1;
				} else
					i++;
				break;
			} else {
				if (myToday < 28)
					d = myToday + 1;
				else if (myToday == 28) {
					m = 3;
					d = 1;
				} else
					i++;
				break;
			}
		}
	}
	console.log(m, d)
	myMonth = myMonth > 9 ? myMonth : '0' + myMonth
	myToday = myToday > 9 ? myToday : '0' + myToday
	m = m > 9 ? m : '0' + m
	d = d > 9 ? d : '0' + d
	obj.createStart = myYear + '-' + myMonth + '-' + myToday
	obj.createEnd = y + '-' + m + '-' + d
	return obj
}
